<template>
	<view>
		<u-cell-group v-for="(item, index) in myReservationLists" :key="index">
			<u-cell-item icon="clock" :title="item.reservation_project"
				:label="$u.timeFormat(item.reservation_time, 'yyyy年mm月dd日')" use-label-slot=true
				:value="item.reservation_docter" :arrow="false" title-style="{font-weight:bold}">

				<u-badge  :count="item.reservation_status==0 ? '未就诊' : '已就诊'" :absolute="false" slot="right-icon"></u-badge>	
							
			</u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	import store from '@/store'
	import AvatarImage from '@/components/avatar-image'
	import SettingKeyEnum from '@/common/enum/setting/Key'
	import SettingModel from '@/common/model/Setting'
	import * as UserApi from '@/api/user'
	import * as ReservationApi from '@/api/reservation'
	import {
		checkLogin
	} from '@/core/app'


	export default {
		components: {
			AvatarImage
		},
		data() {
			return {
				// 正在加载
				isLoading: true,
				// 会员信息
				userInfo: {},
				myReservationLists: {}
			}
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow(options) {
			this.onRefreshPage()
		},

		methods: {

			// 刷新页面
			onRefreshPage() {

				// 判断是否已登录
				this.isLogin = checkLogin()
				// 获取页面数据
				this.getPageData()
			},

			// 获取页面数据11
			getPageData() {
				const app = this
				app.isLoading = true
				// Promise.all([app.getUserInfo(),app.getMyReservationLists()])
				Promise.all([app.getMyReservationLists()])
					.then(() => app.isLoading = false)
			},

			//获取我的预约列表
			getMyReservationLists() {
				const app = this
				return new Promise((resolve, reject) => {
					// !app.isLogin ? resolve(null) : ReservationApi.myReservationLists({}, {
					ReservationApi.myReservationLists({}, {
							load: app.isFirstload
						})
						.then(result => {
							app.myReservationLists = result.data.list.data
							resolve(app.myReservationLists)
						})
						.catch(err => {
							if (err.result && err.result.status == 401) {
								app.isLogin = false
								resolve(null)
							} else {
								reject(err)
							}
						})
				})
			},

			// 获取当前用户信息
			getUserInfo() {
				const app = this
				return new Promise((resolve, reject) => {
					UserApi.info()
						.then(result => {
							app.userInfo = result.data.userInfo
							resolve(app.userInfo)
						})
				})
			}
		}
	}
</script>